﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business;
using System.Text;
using NHibernate.Criterion;
using NHibernate;
using System.Collections;
using ZLCMS.Data.Model;
using ZLCMS.Business.DwzFrame;
using ZLCMS.Business.Config;
using Newtonsoft.Json;
using System.Reflection;
using ZLCMS.Business.Util;
using ZLCMS.Business.TranferParam;
using DotNet.Common.TransferParam;
using DotNet.Common.NHibernateUtil;
using DotNet.Common.NHibernateUtil.QueryFilter;
using NHibernate.Transform;

namespace ZLCMS.Web.SystemManage.Basics.Location
{
    public partial class ProvinceList : System.Web.UI.Page
    {
        protected FrameHelper _framePage;
        
        //public string _province;

        protected void Page_Load(object sender, EventArgs e)
        {
            //初始化全局变量值
            //_province = String.IsNullOrEmpty(Request["province"]) ? "" : Request["province"];

            _framePage = new FrameHelper(this) ;

            if (_framePage.IsAjaxPagerPostBack)
            {
                BindList(_framePage.PageIndex, _framePage.PageSize);
            }
            else
            {
                BindList(1, 20);
            }
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="pageIndex">分页索引</param>
        /// <param name="pageSize">分页大小</param>
        private void BindList(int pageIndex, int pageSize)
        {
            using (ISession session = SessionFactoryHelper.CreateSession())
            {
                QueryFilterList filters = new QueryFilterList();

                string fromSql = " from  DataProvince p  ";

                //if (!string.IsNullOrEmpty(_province.Trim())&&_province!="-1")
                //{
                //    filters.Add(new StringFilter("c.ProvinceCode", "ProvinceCode", _province.Trim(), StringCompairType.Equal));
                //}

                string condtion = "";

                //foreach (DataFilter filter in filters)
                //{
                //    condtion += " and " + filter.GetSection();
                //}

                //获取记录总数
                IQuery cntquery = session.CreateQuery("select count(*)" + fromSql + condtion);
                filters.SetUp(cntquery);

                _framePage.RecordCount = Convert.ToInt32(cntquery.UniqueResult());

                //string select = " select p.* ";

                //获取数据
                IQuery dataquery = session.CreateQuery( fromSql + condtion);
                filters.SetPager(dataquery, pageIndex, pageSize);
                filters.SetUp(dataquery);

                rpt_city.DataSource = dataquery.List<DataProvince>();
                rpt_city.DataBind();
            }
        }
    }
}
